<?php
  include __DIR__."/config/cors.php";
  include __DIR__."/database.php";

  $nid = @$_GET['nid'];
  $username = @$_GET['username'];
  $role = @$_GET['role'];

  if(!isset($username) or !isset($role)){
    echo json_encode([
        "code" => 202,
        "msg"=> "请管理员登陆后在删除"
      ]);
      exit;
  }

  if(!isset($nid)){
    echo json_encode([
        "code" => 203,
        "msg"=> "必要参数传递有误"
      ]);
      exit;
  }

   $db = new DB();
    $sql = "delete from news where id = '$nid'";
    if ($db->insert($sql)) {
        echo json_encode([
            "code" => 200,
            "msg"=>"删除成功"
        ]);
    } else {
        echo json_encode([
            "code" => 204,
            "msg"=> "删除失败: " . $data
        ]);
    }
?>